package classes;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class CadClientes extends JFrame {

	private JPanel contentPane;
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_1;
	private JLabel lblNewLabel_2;
	private JLabel lblNewLabel_3;
	private JLabel lblNewLabel_4;
	private JLabel lblNewLabel_5;
	private JLabel lblNewLabel_6;
	private JLabel lblCnpjcpf;
	private JLabel lblObservao;
	private JTextField tfNome;
	private JTextField tfEndereco;
	private JTextField tfCep;
	private JTextField tfTelefone;
	private JTextField tfSite;
	private JTextField tfEmail;
	private JTextField tfCpf;
	private JTextField tfObservacao;
	private JComboBox cbUf;
	private JButton btnCadastrar;
	private JButton btnConsulta;
	private JTable tbCliente;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CadClientes frame = new CadClientes();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CadClientes() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 446, 517);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(20)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
								.addComponent(getLblCnpjcpf())
								.addComponent(getLblNewLabel())
								.addComponent(getLblNewLabel_1())
								.addComponent(getLblNewLabel_2())
								.addComponent(getLblNewLabel_3())
								.addComponent(getLblNewLabel_5())
								.addComponent(getLblNewLabel_4())
								.addComponent(getLblNewLabel_6()))
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
								.addComponent(getCbUf(), GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)
								.addComponent(getTfEmail())
								.addComponent(getTfSite())
								.addComponent(getTfTelefone())
								.addComponent(getTfCep())
								.addComponent(getTfEndereco())
								.addComponent(getTfNome(), GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
								.addComponent(getTfCpf())))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addContainerGap()
							.addComponent(getLblObservao())
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(getTfObservacao(), GroupLayout.PREFERRED_SIZE, 256, GroupLayout.PREFERRED_SIZE)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(getBtnCadastrar())
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(getBtnConsulta()))))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(34)
							.addComponent(getTbCliente(), GroupLayout.PREFERRED_SIZE, 313, GroupLayout.PREFERRED_SIZE)))
					.addContainerGap(81, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(44)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(getLblNewLabel())
						.addComponent(getTfNome(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(getLblNewLabel_1())
						.addComponent(getTfEndereco(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(getLblNewLabel_2())
						.addComponent(getTfCep(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(getLblNewLabel_3())
						.addComponent(getTfTelefone(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(getCbUf(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(getLblNewLabel_4()))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(getTfSite(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(getLblNewLabel_5()))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(getTfEmail(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(getLblNewLabel_6()))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(getLblCnpjcpf())
						.addComponent(getTfCpf(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(getLblObservao())
						.addComponent(getTfObservacao(), GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(getBtnCadastrar())
						.addComponent(getBtnConsulta()))
					.addPreferredGap(ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
					.addComponent(getTbCliente(), GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE)
					.addGap(31))
		);
		contentPane.setLayout(gl_contentPane);
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("Nome:");
		}
		return lblNewLabel;
	}
	private JLabel getLblNewLabel_1() {
		if (lblNewLabel_1 == null) {
			lblNewLabel_1 = new JLabel("Endere\u00E7o:");
		}
		return lblNewLabel_1;
	}
	private JLabel getLblNewLabel_2() {
		if (lblNewLabel_2 == null) {
			lblNewLabel_2 = new JLabel("Cep:");
		}
		return lblNewLabel_2;
	}
	private JLabel getLblNewLabel_3() {
		if (lblNewLabel_3 == null) {
			lblNewLabel_3 = new JLabel("Telefone:");
		}
		return lblNewLabel_3;
	}
	private JLabel getLblNewLabel_4() {
		if (lblNewLabel_4 == null) {
			lblNewLabel_4 = new JLabel("UF:");
		}
		return lblNewLabel_4;
	}
	private JLabel getLblNewLabel_5() {
		if (lblNewLabel_5 == null) {
			lblNewLabel_5 = new JLabel("Site:");
		}
		return lblNewLabel_5;
	}
	private JLabel getLblNewLabel_6() {
		if (lblNewLabel_6 == null) {
			lblNewLabel_6 = new JLabel("Email:");
		}
		return lblNewLabel_6;
	}
	private JLabel getLblCnpjcpf() {
		if (lblCnpjcpf == null) {
			lblCnpjcpf = new JLabel("CNPJ/CPF:");
		}
		return lblCnpjcpf;
	}
	private JLabel getLblObservao() {
		if (lblObservao == null) {
			lblObservao = new JLabel("Observa\u00E7\u00E3o:");
		}
		return lblObservao;
	}
	private JTextField getTfNome() {
		if (tfNome == null) {
			tfNome = new JTextField();
			tfNome.setColumns(10);
		}
		return tfNome;
	}
	private JTextField getTfEndereco() {
		if (tfEndereco == null) {
			tfEndereco = new JTextField();
			tfEndereco.setColumns(10);
		}
		return tfEndereco;
	}
	private JTextField getTfCep() {
		if (tfCep == null) {
			tfCep = new JTextField();
			tfCep.setColumns(10);
		}
		return tfCep;
	}
	private JTextField getTfTelefone() {
		if (tfTelefone == null) {
			tfTelefone = new JTextField();
			tfTelefone.setColumns(10);
		}
		return tfTelefone;
	}
	private JTextField getTfSite() {
		if (tfSite == null) {
			tfSite = new JTextField();
			tfSite.setColumns(10);
		}
		return tfSite;
	}
	private JTextField getTfEmail() {
		if (tfEmail == null) {
			tfEmail = new JTextField();
			tfEmail.setColumns(10);
		}
		return tfEmail;
	}
	private JTextField getTfCpf() {
		if (tfCpf == null) {
			tfCpf = new JTextField();
			tfCpf.setColumns(10);
		}
		return tfCpf;
	}
	private JTextField getTfObservacao() {
		if (tfObservacao == null) {
			tfObservacao = new JTextField();
			tfObservacao.setColumns(10);
		}
		return tfObservacao;
	}
	private JComboBox getCbUf() {
		if (cbUf == null) {
			cbUf = new JComboBox();
			cbUf.setModel(new DefaultComboBoxModel(new String[] {"AC", "PR", "SP", "RJ"}));
		}
		return cbUf;
	}
	private JButton getBtnCadastrar() {
		if (btnCadastrar == null) {
			btnCadastrar = new JButton("Cadastrar");
			btnCadastrar.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					
					Cliente cliente = new Cliente();
					cliente.setNome(tfNome.getText());
					cliente.setCpf(tfCpf.getText());
					cliente.setUf(cbUf.getSelectedItem().toString());
					cliente.setTelefone(tfTelefone.getText());
					cliente.setEndereco(tfEndereco.getText());
					cliente.setSite(tfSite.getText());
					cliente.setEmail(tfEmail.getText());
					cliente.setObservacao(tfObservacao.getText());
					cliente.setCep(tfCep.getText());
					
					ManipulaClientes mc = new ManipulaClientes();
					
					mc.insereCliente(cliente);
					
				}
			});
		}
		return btnCadastrar;
	}
	private JButton getBtnConsulta() {
		if (btnConsulta == null) {
			btnConsulta = new JButton("Consulta");
			btnConsulta.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					
					ManipulaClientes mc = new ManipulaClientes();
					
					mc.consultaClientes();
				}
			});
		}
		return btnConsulta;
	}
	private JTable getTbCliente() {
		if (tbCliente == null) {
			tbCliente = new JTable();
			tbCliente.setModel(new DefaultTableModel(
				new Object[][] {
					{null, null, null, null, null, null, null, null, null},
				},
				new String[] {
					"New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column", "New column"
				}
			));
		}
		return tbCliente;
	}
}
